package com.orchard.xpz.service.payInfo.Impl;

import com.github.pagehelper.PageHelper;
import com.orchard.xpz.dao.PayInfoDao;
import com.orchard.xpz.entity.payInfo.PayInfo;
import com.orchard.xpz.service.payInfo.PayInfoService;
import com.orchard.xpz.utils.PageResultData;
import com.orchard.xpz.utils.UserRuntime;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * @TaskCode:
 * @description:
 * @author: minshuai.chen
 * @create: 2022/4/21 16:57
 **/
@Service
public class PayInfoServiceImpl implements PayInfoService {

    @Autowired
    private PayInfoDao payInfoDao;

    @Override
    public PageResultData<PayInfo> getPageList(PayInfo payInfo) {
        PageHelper.startPage(payInfo.getPageNum(),payInfo.getPageSize());
        List<PayInfo> list = payInfoDao.getList(payInfo);
        PageResultData<PayInfo> pageResultData = new PageResultData<>(list, payInfo.getPageNum(), payInfo.getPageSize());
        return pageResultData;
    }

    @Override
    public boolean saveOrUpdate(PayInfo payInfo) {
        payInfo.setGardenId(payInfo.getGardenPlot().getGardenId());
        if (ObjectUtils.isEmpty(payInfo.getPayId())){
            payInfo.setCreateName(UserRuntime.getUser().getUserName());
            payInfo.setCreateTime(LocalDate.now());
            int i = payInfoDao.insertSelective(payInfo);
            return i > 0? true : false;
        }else {
            payInfo.setUpdateTime(LocalDate.now());
            payInfo.setUpdateName(UserRuntime.getUser().getUserName());
            int i = payInfoDao.updateByPrimaryKeySelective(payInfo);
            return i > 0? true : false;
        }
    }

    @Override
    public boolean deltePlot(String id) {
        return payInfoDao.deleteByPrimaryKey(id) > 0? true : false;
    }
}
